//------------------------------------------------------------------------------
// Classification: COMPANY UNCLASSIFIED
//
// Copyright (c) Terma A/S
// All rights reserved
//------------------------------------------------------------------------------

package dk.snaveponyklub.util;

public class Logger {

    private static void fast(String log) {
        System.out.println(log + " " + lineBrokenStackTraceElementsToString(new Throwable().getStackTrace()));
    }

    public static void debug(String log) {
        fast("debug: " + log);
    }

    public static void info(String log) {
        fast("info: " + log);
    }

    public static void error(String log) {
        fast("error: " + log);
    }

    public static String lineBrokenStackTraceElementsToString(StackTraceElement[] stackTraceElements) {
        StringBuffer trace = new StringBuffer();
        trace.append("\n");
        for (int i = 1; i < stackTraceElements.length; i++) {
            if (i > 1) {
                trace.append(",\n");
            }
            trace.append(stackTraceElements[i].getClassName());
            trace.append(".");
            trace.append(stackTraceElements[i].getMethodName());
            trace.append("(");
            if (stackTraceElements[i].isNativeMethod()) {
                trace.append("Native Method");
            } else {
                trace.append(stackTraceElements[i].getFileName());
                trace.append(":");
                trace.append(stackTraceElements[i].getLineNumber());
            }
            trace.append(")");
        }
        return trace.toString();
    }
}